package com.chap4;

import com.chap1.tools.SleepTools;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * <code>ThreadLocalMemoryLeak</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-03-28 8:23
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class ThreadLocalMemoryLeak {
    private static final int TASK_LOOP_SIZE = 500;

    final static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5,5,1,
            TimeUnit.MINUTES,new LinkedBlockingDeque<>());

    public static void main(String[] args) {
        SleepTools.ms(4000);
        for (int i = 0; i < TASK_LOOP_SIZE; i++) {
            poolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    SleepTools.ms(500);
                    System.out.println("use local varaible");
                }
            });
            SleepTools.ms(100);
        }
        System.out.println("pool execute over");
    }
}
